<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>高德地图静态地图测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input, select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        button {
            background-color: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 4px;
            background-color: #f9f9f9;
        }
        .map-image {
            max-width: 100%;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <h1>高德地图静态地图测试</h1>
    
    <form id="mapForm">
        <div class="form-group">
            <label for="longitude">经度:</label>
            <input type="text" id="longitude" value="116.481485" required>
        </div>
        
        <div class="form-group">
            <label for="latitude">纬度:</label>
            <input type="text" id="latitude" value="39.990464" required>
        </div>
        
        <div class="form-group">
            <label for="zoom">缩放级别:</label>
            <select id="zoom">
                <option value="1">1</option>
                <option value="5">5</option>
                <option value="10" selected>10</option>
                <option value="15">15</option>
                <option value="17">17</option>
            </select>
        </div>
        
        <div class="form-group">
            <label for="size">地图大小:</label>
            <select id="size">
                <option value="400*400" selected>400x400</option>
                <option value="500*500">500x500</option>
                <option value="600*400">600x400</option>
                <option value="750*300">750x300</option>
            </select>
        </div>
        
        <button type="submit">生成地图</button>
    </form>
    
    <div id="result" class="result" style="display: none;">
        <h3>生成结果:</h3>
        <div id="mapContainer"></div>
        <div id="urlContainer"></div>
    </div>

    <script>
        document.getElementById('mapForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const longitude = document.getElementById('longitude').value;
            const latitude = document.getElementById('latitude').value;
            const zoom = document.getElementById('zoom').value;
            const size = document.getElementById('size').value;
            
            try {
                const response = await fetch('/api/map/simple', {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    params: {
                        longitude: longitude,
                        latitude: latitude,
                        zoom: zoom
                    }
                });
                
                if (response.ok) {
                    const data = await response.json();
                    const mapUrl = data.url;
                    
                    // 显示结果
                    document.getElementById('result').style.display = 'block';
                    document.getElementById('mapContainer').innerHTML = `
                        <img src="${mapUrl}" alt="静态地图" class="map-image">
                    `;
                    document.getElementById('urlContainer').innerHTML = `
                        <p><strong>地图URL:</strong></p>
                        <input type="text" value="${mapUrl}" readonly style="width: 100%; padding: 8px;">
                    `;
                } else {
                    alert('生成地图失败: ' + response.statusText);
                }
            } catch (error) {
                alert('请求失败: ' + error.message);
            }
        });
    </script>
</body>
</html> 